<!DOCTYPE html>
<html lang="en">
	[#escape x as x?html]
	<head>
		<meta charset="utf-8">
		<title>登录-${setting.name}</title>
		[#include "/common/include.ftl"/]
		<link type="text/css" rel="stylesheet" href="${base}/resource/css/register.css">
		<script type="text/javascript" src="${base}/resource/js/encrypt.js"></script>
		<script type="text/javascript">
			var flag = false;
			$(function() {
				var rm = $.cookie("rm");
				if (rm != undefined && rm != '') {
					$("#username").val(rm);
					$("#password").focus();
				} else {
					$("#username").focus();
				}
				$("input").keydown(function(event) {
					if (event.keyCode == 13) {
						login();
					}
				});

				[#if showCode?? && showCode]
					$(".showcode").show();
				[#else]
					$(".showcode").hide();
				[/#if]
			});

			function refreshCaptcha() {
				$("#captchImage").attr("src", "${base}/captcha.jhtml?captchaId=${captchaId}&timestamp=" + new Date().getTime());
			}

			function login() {
				if (flag) {
					return;
				}
				var code;
				var username = $.trim($("#username").val());
				if (username.length == 0) {
					oDialog.prompt("请输入你的帐号");
					return;
				}
				var password = $("#password").val();
				if ($.trim(password).length == 0) {
					oDialog.prompt("请输入你的密码");
					return;
				}
				if ($("#captchaCode:visible").length == 1) {
					code = $.trim($("#captchaCode").val());
					if (code == '') {
						oDialog.prompt("请输入验证码");
						return;
					}
				}
				var remember = $("#remember:checked").length == 1;
				flag = true;
				ajax({
					url : base + "/publicKey.jhtml",
					type : "GET",
					dataType : "json",
					cache : false,
					showError : true,
					loading : '正在登录...',
					success : function(data) {
						var rsaKey = new RSAKey();
						rsaKey.setPublic(b64tohex(data.modulus), b64tohex(data.exponent));
						password = hex2b64(rsaKey.encrypt(password));
						$.ajax({
							url : base + "/loginVerify.jhtml",
							type : "POST",
							dataType : "json",
							data : {
								username : username,
								password : password,
								captcha : code,
								captchaId : "${captchaId}",
								remember : remember
							},
							cache : false,
							success : function(data) {
								if (data.error == undefined || data.error == '') {
									window.location = "${redirectUrl!'/index.jhtml'}";
								} else {
									oDialog.prompt(data.error);
									if (data.showCode) {
										refreshCaptcha();
										$(".showcode").show();
									}
									flag = false;
								}
							}
						});
					}
				});
			}
		</script>
	</head>
	<body class="customer">
		<div class="top w1">
			[#include "/common/header-top.ftl"/]
			<div class="top-search w">
				<div id="header-logo" class="text-log">
					<div class="t-log">
						<a href="${base}/index.jhtml">
							<img src="[@Pic pic=setting.logo/]" width="200" height="60">
						</a>
					</div>
					<div class="t-text">
						欢迎登录
					</div>
				</div>
			</div>
		</div>
		<div id="P_login">
			<div class="login-warp">
				<div class="lg-img"><img src="${base}/resource/images/upload/login.png">
				</div>
				<div class="login-form">
					<div class="lg-h">
						<h2>账号</h2><a href="${base}/register.jhtml">用户注册</a>
					</div>
					<div class="lg-i">
						<input type="text" placeholder="用户名/手机号/邮箱" class="username placeholder" id="username" AUTOCOMPLETE='off' />
					</div>
					<div class="lg-h">
						<h2>密码</h2>
					</div>
					<div class="lg-i">
						<input type="password" placeholder="密码" class="password placeholder" id="password">
					</div>
					<div class="lg-h showcode">
						<h2>验证码</h2>
					</div>
					<div class="lg-i captcha-wrap showcode">
						<input type="text" placeholder="验证码" class="captcha placeholder" id="captchaCode">
						<img id="captchImage" src="${base}/captcha.jhtml?captchaId=${captchaId}" onclick="refreshCaptcha()"/>
						<a href="javascript:refreshCaptcha();">看不清楚?</a>
					</div>
					<div class="lg-h lg-a-h">
						<input type="checkbox" id="remember">
						<label for="remember">自动登录</label><a href="${base}/forget/index.jhtml">忘记密码?</a>
					</div>
					<div class="lg-i">
						<input type="button" value="登录" class="hp-btn-login" onclick="login()"/>
					</div>
				</div>
			</div>
		</div>
		
		[#include "common/footer-simple.ftl"]
	</body>
	[/#escape]
</html>